package netGaming;

import gameBasicElements.*;
import gameEngine.GameInfo;

import java.io.*;

/**
 * @author Wojciech Łopata
 *
 */

public class ServerDataSender
{
	private ObjectOutputStream output;
	private final GameInfo infoSource;
	
	public ServerDataSender(OutputStream outputStream, GameInfo infoSource) throws IOException
	{
		this.infoSource = infoSource;
		output = new ObjectOutputStream(outputStream);
	}
	
	public synchronized void sendGameStatus() throws IOException
	{
		output.writeObject(ServerMessageType.GAME_STATUS);
		output.writeObject(new TransportableOneTurnGameInfo(infoSource));
	}
	
	public synchronized void informAboutEndOfGame(ScoreBoard finalScores) throws IOException
	{
		output.writeObject(ServerMessageType.FINAL_SCORES);
		output.writeObject(finalScores);
	}
	

	public synchronized void sendMoveRequest() throws IOException
	{
		output.writeObject(ServerMessageType.MOVE_REQUEST);
	}

	public synchronized void sendGameBeginInfo(PlayerColor thisPlayerColor) throws IOException
	{
		output.writeObject(ServerMessageType.GAME_BEGIN_INFO);
		output.writeObject(thisPlayerColor);
		output.writeObject(new TransportableOneTurnGameInfo(infoSource));
	}
}
